-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add timeseries section to model schema #99
Conversation
@jetuk there is quite a bit left to do here but it would be good to get your opinion on the approach. I have a few queries:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had a quick read through. I've left a couple of comments. I think this is what I was thinking it would look like.
@jetuk I've had a go at some resampling using polars. It still needs some work but one change that might simplify the code a bit would be to use chrono across the project instead of time-rs. This would also open up the possibility of using polars duration strings to specify model timestep frequency and the polars |
I think the polars integration and the duration strings are a good argument for switching to chrono. How should we do that? Should we do a separate PR to swap, and the rebase this against it? |
@jetuk could you take another look at this. I responded to most of your comments thought there are still some issues to fix:
At least the first of these is probably worth doing in another PR? |
That's probably OK. There are other TODOs and unfinished items at the moment. We can get this framework in and work on it.
Yes, I had some ideas, but nothing implemented. Can we merge this with a limitation? That method could do a check that all time-steps have the same duration and panic if not?
Yes!
This could mirror the "sub-names" for the nodes? I hadn't anticipated a schema parameter creating many core parameters.
Probably all of them can be addressed with additional updates? |
@jetuk this is ready for another look. All your original comments should be addressed in some fashion. One update that's probably necessary is adding the |
I think there are other approaches, but they will delay this PR further. Two ideas:
So, probably (1) would just remove this boiler plate. I guess it might be more efficient to do (1) in a separate PR and then update this one? Assuming we can do that in the short-term to not delay this further. |
I forgot that the proc macros you created in the v1 schema did this. Looking at them, we should be able to copy them across without too many modifications. I can have a go in a separate PR this evening. |
This supports using PyParameter as an index parameter with updated schema to define the return type of the Python method.
Restores some removed functions required for the highs solver. Adds highs feature to CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. I've left a few, but minor, comments to improve docstrings and tidy things up etc.
I think this might need a cargo fmt
too.
@@ -58,6 +58,10 @@ impl PywrDuration { | |||
pub fn fractional_days(&self) -> f64 { | |||
self.0.num_seconds() as f64 / SECS_IN_DAY as f64 | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add docstring. Would be good to make the one above a proper docstring as well.
@@ -412,8 +445,9 @@ impl PywrModel { | |||
Timestepper::default() | |||
}); | |||
|
|||
let nodes = v1 | |||
let nodes_and_ts: Vec<NodeAndTimeseries> = v1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worthwhile adding some comments here about this process.
pywr-schema/src/model.rs
Outdated
(None, None) | ||
}; | ||
|
||
ts_data.extend(param_ts_data.into_iter().flatten()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can move this up into the above if let Some(v1_parameters) ...
block to avoid wrapping in an Option
?
|
||
if durations.len() > 1 { | ||
// Non-uniform timestep are not yet supported | ||
todo!(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the comment in the todo!()
macro.
.time() | ||
.step_duration() | ||
.whole_nanoseconds() | ||
.expect("Nano seconds could not be extracted from model step duration"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a TimesreiesError
variant?
pywr-schema/src/model.rs
Outdated
use crate::outputs::Output; | ||
use crate::parameters::{MetricFloatReference, TryIntoV2Parameter}; | ||
use crate::parameters::{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some unused imports to resolve here.
@@ -5,6 +5,7 @@ use crate::nodes::NodeAttribute; | |||
use crate::parameters::{ | |||
DynamicFloatValue, IntoV2Parameter, NodeReference, ParameterMeta, TryFromV1Parameter, TryIntoV2Parameter, | |||
}; | |||
use crate::timeseries::{self, LoadedTimeseriesCollection}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import self
pywr-schema/src/parameters/offset.rs
Outdated
@@ -1,5 +1,6 @@ | |||
use crate::data_tables::LoadedTableCollection; | |||
use crate::parameters::{ConstantValue, DynamicFloatValue, DynamicFloatValueType, ParameterMeta}; | |||
use crate::parameters::{ConstantValue, DynamicFloatValue, DynamicFloatValueType, ParameterMeta, VariableSettings}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import VariableSettings
@@ -0,0 +1,245 @@ | |||
use chrono::TimeDelta; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import
pywr-schema/src/timeseries/mod.rs
Outdated
use pywr_core::parameters::{Array1Parameter, Array2Parameter, ParameterIndex}; | ||
use pywr_core::PywrError; | ||
use pywr_v1_schema::tables::TableVec; | ||
use std::sync::Arc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import
@jetuk thanks for the review. I think I've addressed all your comments apart from the one I reply to above. |
Should we remove |
yeah, I did think of doing this earlier on. At this stage of development it could probably just be removed? |
@Batch21 Are you finished with this now? |
Yes, though I did spot another issue when removing the df parameter. The polars timeseries backend does not load gzip files, which will be needed when the test that loads the |
No description provided.